/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utilidades;

import java.awt.Color;
import java.awt.event.KeyEvent;
import javax.swing.JProgressBar;
import javax.swing.JTextField;
import net.java.balloontip.BalloonTip;
import net.java.balloontip.styles.MinimalBalloonStyle;

/**
 *
 * @author Lelouch
 */
public class ValidaBarras extends ValidaEnteros {
	JProgressBar pb;
	boolean usado;

	public JProgressBar getPb () {
		return this.pb;
	}

	public ValidaBarras (JTextField tf, JProgressBar pb) {
		super (tf);
		usado = false;
		this.pb = pb;
	}

	@Override
	public void keyTyped (KeyEvent e) {
		bt.setVisible (false);
		super.keyTyped (e);
		char caracter = e.getKeyChar ();

		if ((caracter < '0' || caracter > '9') && (caracter != KeyEvent.VK_BACK_SPACE && caracter != KeyEvent.VK_DELETE)) {
			bt.setVisible (true);
			e.consume ();
		}
		else if ((caracter == KeyEvent.VK_BACK_SPACE || caracter == KeyEvent.VK_DELETE) && tf.getText ().isEmpty ()) {
			if (usado) {
				pb.setValue (pb.getValue () - 1);
				usado = false;
			}
			else {
				e.consume ();
			}
		}
		else {
			if (tf.getText ().isEmpty () && (caracter != KeyEvent.VK_BACK_SPACE && caracter != KeyEvent.VK_DELETE) && !usado) {
				pb.setValue (pb.getValue () + 1);
				usado = true;
			}
		}
	}

}



